const express = require('express');
const router = express.Router();

/**
 * API文档路由
 */
router.get('/', (req, res) => {
  res.json({
    title: '思研社平台 API 文档',
    version: '1.0.0',
    description: '思研社平台后端API接口文档',
    baseUrl: `${req.protocol}://${req.get('host')}/api`,
    endpoints: {
      auth: {
        description: '用户认证相关接口',
        basePath: '/auth',
        endpoints: [
          { method: 'POST', path: '/register', description: '用户注册' },
          { method: 'POST', path: '/login', description: '用户登录' },
          { method: 'POST', path: '/logout', description: '用户登出' },
          { method: 'POST', path: '/refresh-token', description: '刷新令牌' },
          { method: 'POST', path: '/forgot-password', description: '忘记密码' },
          { method: 'POST', path: '/reset-password', description: '重置密码' },
          { method: 'POST', path: '/verify-email', description: '邮箱验证' },
          { method: 'POST', path: '/send-sms', description: '发送短信验证码' },
          { method: 'POST', path: '/verify-sms', description: '验证短信验证码' }
        ]
      },
      user: {
        description: '用户管理相关接口',
        basePath: '/user',
        endpoints: [
          { method: 'GET', path: '/profile', description: '获取用户信息' },
          { method: 'PUT', path: '/profile', description: '更新用户信息' },
          { method: 'PUT', path: '/avatar', description: '更新用户头像' },
          { method: 'PUT', path: '/password', description: '修改密码' },
          { method: 'GET', path: '/courses', description: '获取用户课程列表' },
          { method: 'GET', path: '/orders', description: '获取用户订单列表' },
          { method: 'GET', path: '/favorites', description: '获取用户收藏列表' },
          { method: 'POST', path: '/favorites/:courseId', description: '添加收藏' },
          { method: 'DELETE', path: '/favorites/:courseId', description: '取消收藏' }
        ]
      },
      course: {
        description: '课程管理相关接口',
        basePath: '/course',
        endpoints: [
          { method: 'GET', path: '/', description: '获取课程列表' },
          { method: 'GET', path: '/:id', description: '获取课程详情' },
          { method: 'GET', path: '/:id/chapters', description: '获取课程章节' },
          { method: 'GET', path: '/:id/comments', description: '获取课程评论' },
          { method: 'POST', path: '/:id/comments', description: '发表课程评论' },
          { method: 'GET', path: '/search', description: '搜索课程' },
          { method: 'GET', path: '/categories', description: '获取课程分类' }
        ]
      },
      admin: {
        description: '管理员相关接口',
        basePath: '/admin',
        endpoints: [
          { method: 'GET', path: '/users', description: '获取用户列表' },
          { method: 'PUT', path: '/users/:id/status', description: '更新用户状态' },
          { method: 'GET', path: '/courses', description: '获取课程列表' },
          { method: 'POST', path: '/courses', description: '创建课程' },
          { method: 'PUT', path: '/courses/:id', description: '更新课程' },
          { method: 'DELETE', path: '/courses/:id', description: '删除课程' },
          { method: 'GET', path: '/orders', description: '获取订单列表' },
          { method: 'PUT', path: '/orders/:id/status', description: '更新订单状态' },
          { method: 'GET', path: '/statistics', description: '获取统计数据' }
        ]
      },
      teacher: {
        description: '教师相关接口',
        basePath: '/teacher',
        endpoints: [
          { method: 'GET', path: '/courses', description: '获取教师课程列表' },
          { method: 'POST', path: '/courses', description: '创建课程' },
          { method: 'PUT', path: '/courses/:id', description: '更新课程' },
          { method: 'GET', path: '/students', description: '获取学生列表' },
          { method: 'GET', path: '/analytics', description: '获取教学分析数据' }
        ]
      },
      student: {
        description: '学生相关接口',
        basePath: '/student',
        endpoints: [
          { method: 'GET', path: '/enrolled-courses', description: '获取已报名课程' },
          { method: 'GET', path: '/learning-progress', description: '获取学习进度' },
          { method: 'POST', path: '/courses/:id/enroll', description: '报名课程' },
          { method: 'GET', path: '/certificates', description: '获取证书列表' }
        ]
      },
      live: {
        description: '直播相关接口',
        basePath: '/live',
        endpoints: [
          { method: 'GET', path: '/rooms', description: '获取直播房间列表' },
          { method: 'POST', path: '/rooms', description: '创建直播房间' },
          { method: 'GET', path: '/rooms/:id', description: '获取直播房间详情' },
          { method: 'PUT', path: '/rooms/:id/status', description: '更新直播状态' },
          { method: 'GET', path: '/rooms/:id/chat', description: '获取聊天记录' }
        ]
      },
      payment: {
        description: '支付相关接口',
        basePath: '/payment',
        endpoints: [
          { method: 'POST', path: '/create-order', description: '创建支付订单' },
          { method: 'POST', path: '/callback', description: '支付回调处理' },
          { method: 'GET', path: '/orders', description: '获取订单列表' },
          { method: 'GET', path: '/orders/:id', description: '获取订单详情' },
          { method: 'PUT', path: '/orders/:id/cancel', description: '取消订单' },
          { method: 'POST', path: '/orders/:id/refund', description: '申请退款' }
        ]
      },
      upload: {
        description: '文件上传相关接口',
        basePath: '/upload',
        endpoints: [
          { method: 'POST', path: '/image', description: '上传图片' },
          { method: 'POST', path: '/video', description: '上传视频' },
          { method: 'POST', path: '/audio', description: '上传音频' },
          { method: 'POST', path: '/document', description: '上传文档' },
          { method: 'POST', path: '/batch', description: '批量上传' },
          { method: 'DELETE', path: '/:type/:filename', description: '删除文件' },
          { method: 'GET', path: '/:type/:filename', description: '获取文件信息' }
        ]
      },
      notification: {
        description: '通知相关接口',
        basePath: '/notification',
        endpoints: [
          { method: 'GET', path: '/', description: '获取通知列表' },
          { method: 'GET', path: '/unread-count', description: '获取未读通知数量' },
          { method: 'PUT', path: '/:id/read', description: '标记通知为已读' },
          { method: 'PUT', path: '/all/read', description: '标记所有通知为已读' },
          { method: 'DELETE', path: '/:id', description: '删除通知' },
          { method: 'DELETE', path: '/batch', description: '批量删除通知' }
        ]
      },
      statistics: {
        description: '统计相关接口',
        basePath: '/statistics',
        endpoints: [
          { method: 'GET', path: '/overall', description: '获取总体统计数据' },
          { method: 'GET', path: '/users', description: '获取用户统计数据' },
          { method: 'GET', path: '/courses', description: '获取课程统计数据' },
          { method: 'GET', path: '/orders', description: '获取订单统计数据' },
          { method: 'GET', path: '/revenue', description: '获取收入统计数据' },
          { method: 'GET', path: '/learning', description: '获取学习统计数据' }
        ]
      }
    },
    authentication: {
      type: 'Bearer Token',
      header: 'Authorization: Bearer <token>',
      description: '大部分API需要JWT认证，请在请求头中包含有效的Bearer Token'
    },
    responseFormat: {
      success: {
        code: 200,
        message: '操作成功',
        data: '响应数据'
      },
      error: {
        code: 400,
        message: '错误信息'
      }
    },
    statusCodes: {
      200: '请求成功',
      201: '创建成功',
      400: '请求参数错误',
      401: '未授权',
      403: '权限不足',
      404: '资源不存在',
      429: '请求过于频繁',
      500: '服务器内部错误'
    }
  });
});

module.exports = router; 